import os

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


def db_connect(app: Flask) -> None:
    # 设置数据库文件的存储位置
    base_dir = os.path.abspath(os.path.dirname(__file__))
    app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{base_dir}/my_database.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # 关闭追踪修改

    db.init_app(app)

    with app.app_context():
        db.create_all()
